import org.w3c.dom.ls.LSException;

public class SingleLinkedList {
    static class ListNode {
        public int val;
        public ListNode next;

        public ListNode(int val) {
            this.val = val;

        }
        public ListNode(){

        };
    }

    public ListNode head;
    public boolean chkPalindrome(){
        if(head==null){
            return false;
        }
        //找到中间结点

        ListNode fast=head;
        ListNode slow=head;
        while (fast!=null&&fast.next!=null){
            fast=fast.next.next;
            slow=slow.next;
        }

        //反转
        ListNode cur=slow.next;
        while (cur!=null){
            ListNode curN=cur.next;
            cur.next=slow;
            slow=cur;
            cur=curN;
        }

        //判断
        while (head!=slow){
            if(head.val!=slow.val){
                return false;
            }
            if(head.next==slow){//偶数情况
                return  true;
            }
            head=head.next;
            slow=slow.next;
        }
        return true;

    }
}
